package com.redlion.object;

import org.andengine.entity.sprite.AnimatedSprite;
import org.andengine.entity.sprite.Sprite;
import org.andengine.entity.sprite.AnimatedSprite.IAnimationListener;
import org.andengine.extension.physics.box2d.PhysicsFactory;
import org.andengine.extension.physics.box2d.PhysicsWorld;
import org.andengine.opengl.texture.region.ITextureRegion;
import org.andengine.opengl.texture.region.ITiledTextureRegion;
import org.andengine.opengl.texture.region.TextureRegion;

import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.BodyDef.BodyType;
import com.redlion.Game;

public abstract class AbstractAnimationObject {
	public AnimatedSprite sprite;
	public Body body;
	protected ITiledTextureRegion mTiledTextureRegion;

	public AbstractAnimationObject(Vector2 position, ITiledTextureRegion textureRegion, FixtureDef fixtureDef) {
		this.mTiledTextureRegion = textureRegion;
		createAnimation(position.x, position.y);
		createBody(fixtureDef);
	}

	public AbstractAnimationObject(ITiledTextureRegion textureRegion, FixtureDef fixtureDef) {
		this.mTiledTextureRegion = textureRegion;
		createAnimation();
		createBody(fixtureDef);
	}

	public void animate(int frameDuration) {
		if (getAnimationListener() != null)
			sprite.animate(frameDuration, getAnimationListener());
		else
			sprite.animate(frameDuration);
	}

	public void animate(int frameDuration, int loopCount) {
		if (getAnimationListener() != null)
			sprite.animate(frameDuration, loopCount, getAnimationListener());
		else
			sprite.animate(frameDuration, loopCount);
	}

	protected abstract void createAnimation();

	protected abstract void createAnimation(float px, float py);

	protected abstract void createBody(FixtureDef fixtureDef);

	protected abstract void update(float delta);

	protected abstract IAnimationListener getAnimationListener();

}
